"""
@name : 3-4.线程锁-条件锁
@author : wenyao
@projectname: sanchuanglianxi
"""
#条件锁
#类名：Condition
#该机制会使得线程等待，只有满足某条件的时候，才释放n个线程
#wait_for :等待函数返回结果，True才释放一个线程
#wait: 一次性释放n个wait

import threading

#print(threading.enumerate())

lock = threading.Condition()
def task(i):
    with lock:
        print(f"start condition {i}")
        lock.wait()
        print(f"run the thread {i}")

for i in range(10):
    t = threading.Thread(target=task, args = (i,))
    t.start()

#print(threading.enumerate())
#
while True:
    inp = input(">>>")
    if inp.isdigit():
        with lock:
            lock.notify(int(inp))
#             #这个方法接收一个整数，表示让多少个线程通过
#             #lock.notify() 默认一个
#
#         #固定语法
#         # lock.acquire()
#         # lock.notify()
#         # lock.release()
